{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "7a114b7f",
   "metadata": {},
   "source": [
    "# week02课堂笔记\n",
    "\n",
    "## 一、观察标准库\n",
    "### sys --- 系统相关的参数和函数  \n",
    "```sys.platform``` 本字符串是一个平台标识符。  \n",
    "```sys.version``` 是一个包含 Python 解释器版本号加编译版本号以及所用编译器等额外信息的字符串。\n",
    "```\n",
    ">>> import sys\n",
    ">>> sys.platform\n",
    "'win32'\n",
    ">>> print(sys.version)\n",
    "3.8.8 (default, Apr 13 2021, 15:08:03) [MSC v.1916 64 bit (AMD64)]\n",
    "```\n",
    "### os --- 多种操作系统接口\n",
    "```os.getcwd()``` 返回表示当前工作目录的字符串。  \n",
    "```os.environ``` 一个表示字符串环境的 mapping (映射) 对象。  \n",
    "```os.getenv(key, default=None)``` 如果存在，返回环境变量 key 的值，否则返回 default。\n",
    "\n",
    "\n",
    "```\n",
    ">>> import os\n",
    ">>> os.getcwd()\n",
    "'C:\\\\Users\\\\86159'\n",
    ">>> os.environ\n",
    "environ({'ALLUSERSPROFILE': 'C:\\\\ProgramData', 'APPDATA': 'C:\\\\Users\\\\86159\\\\AppData\\\\Roaming', 'ASL.LOG': 'Destination=file', 'COMMONPROGRAMFILES': 'C:\\\\Program Files\\\\Common Files', 'COMMONPROGRAMFILES(X86)': 'C:\\\\Program Files (x86)\\\\Common Files', 'COMMONPROGRAMW6432': 'C:\\\\Program Files\\\\Common Files', 'COMPUTERNAME': '阿武', 'COMSPEC': 'C:\\\\Windows\\\\system32\\\\cmd.exe', 'DRIVERDATA': 'C:\\\\Windows\\\\System32\\\\Drivers\\\\DriverData', 'HOMEDRIVE': 'C:', 'HOMEPATH': '\\\\Users\\\\86159', 'INTEL_DEV_REDIST': 'C:\\\\Program Files (x86)\\\\Common Files\\\\Intel\\\\Shared Libraries\\\\', 'LOCALAPPDATA': 'C:\\\\Users\\\\86159\\\\AppData\\\\Local', 'LOGONSERVER': '\\\\\\\\阿武', 'MIC_LD_LIBRARY_PATH': 'C:\\\\Program Files (x86)\\\\Common Files\\\\Intel\\\\Shared Libraries\\\\compiler\\\\lib\\\\mic', 'NUMBER_OF_PROCESSORS': '12', 'ONEDRIVE': 'C:\\\\Users\\\\86159\\\\OneDrive', 'ONEDRIVECONSUMER': 'C:\\\\Users\\\\86159\\\\OneDrive', 'OS': 'Windows_NT', 'PATH': 'C:\\\\Program Files (x86)\\\\Common Files\\\\Intel\\\\Shared Libraries\\\\redist\\\\intel64\\\\compiler;D:\\\\Program Files\\\\Anaconda3;D:\\\\Program Files\\\\Anaconda3\\\\Library\\\\mingw-w64\\\\bin;D:\\\\Program Files\\\\Anaconda3\\\\Library\\\\usr\\\\bin;D:\\\\Program Files\\\\Anaconda3\\\\Library\\\\bin;D:\\\\Program Files\\\\Anaconda3\\\\Scripts;C:\\\\Windows\\\\system32;C:\\\\Windows;C:\\\\Windows\\\\System32\\\\Wbem;C:\\\\Windows\\\\System32\\\\WindowsPowerShell\\\\v1.0\\\\;C:\\\\Windows\\\\System32\\\\OpenSSH\\\\;C:\\\\Users\\\\86159\\\\AppData\\\\Local\\\\Microsoft\\\\WindowsApps;C:\\\\Users\\\\86159\\\\AppData\\\\Local\\\\GitHubDesktop\\\\bin;D:\\\\Thunder\\\\pycharm-professional\\\\PyCharm 2021.2.1\\\\bin;', 'PATHEXT': '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC', 'PROCESSOR_ARCHITECTURE': 'AMD64', 'PROCESSOR_IDENTIFIER': 'AMD64 Family 23 Model 96 Stepping 1, AuthenticAMD', 'PROCESSOR_LEVEL': '23', 'PROCESSOR_REVISION': '6001', 'PROGRAMDATA': 'C:\\\\ProgramData', 'PROGRAMFILES': 'C:\\\\Program Files', 'PROGRAMFILES(X86)': 'C:\\\\Program Files (x86)', 'PROGRAMW6432': 'C:\\\\Program Files', 'PROMPT': '$P$G', 'PSMODULEPATH': 'C:\\\\Program Files\\\\WindowsPowerShell\\\\Modules;C:\\\\Windows\\\\system32\\\\WindowsPowerShell\\\\v1.0\\\\Modules', 'PUBLIC': 'C:\\\\Users\\\\Public', 'PYCHARM': 'D:\\\\Thunder\\\\pycharm-professional\\\\PyCharm 2021.2.1\\\\bin;', 'SESSIONNAME': 'Console', 'SYSTEMDRIVE': 'C:', 'SYSTEMROOT': 'C:\\\\Windows', 'TEMP': 'C:\\\\Users\\\\86159\\\\AppData\\\\Local\\\\Temp', 'TMP': 'C:\\\\Users\\\\86159\\\\AppData\\\\Local\\\\Temp', 'USERDOMAIN': '阿武', 'USERDOMAIN_ROAMINGPROFILE': '阿武', 'USERNAME': '86159', 'USERPROFILE': 'C:\\\\Users\\\\86159', 'WINDIR': 'C:\\\\Windows'})\n",
    "\n",
    "```\n",
    "\n",
    "### datetime --- 基本的日期和时间类型\n",
    "```datetime.date()``` 返回具有同样 year, month 和 day 值的 date 对象。  \n",
    "```date.today()``` 返回当前的本地日期。\n",
    "```\n",
    ">>> import datetime\n",
    ">>> datetime.date.today()\n",
    "datetime.date(2021, 9, 30)\n",
    ">>> datetime.date.today().year\n",
    "2021\n",
    ">>> datetime.date.today().month\n",
    "9\n",
    ">>> datetime.date.today().day\n",
    "30\n",
    ">>> datetime.date.isoformat(datetime.date.today())\n",
    "'2021-09-30'\n",
    "```\n",
    "### time --- 时间的访问和转换\n",
    "```time.strftime(format)``` 返回一个由显式格式字符串所指明的代表时间的字符串。  \n",
    "```%H``` 以补零后的十进制数表示的小时（24 小时制）。  \n",
    "```%M``` 补零后，以十进制数显示的分钟。  \n",
    "```%A``` 本地化的星期中每日的完整名称。  \n",
    "```%p``` 本地化的 AM 或 PM 。  \n",
    "```time.time() → float``` 返回以浮点数表示的从 epoch 开始的秒数的时间值。\n",
    "```\n",
    ">>> import time\n",
    ">>> time.strftime(\"%H:%M\")\n",
    "'00:28'\n",
    ">>> time.strftime(\"%A %p\")\n",
    "'Thursday AM'\n",
    ">>> time.time()\n",
    "1632932952.7641268\n",
    "\n",
    "```\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "889e9b65",
   "metadata": {},
   "source": [
    "## html --- 超文本标记语言支持\n",
    "## ```html.escape(s, quote=True)``` 将字符串 s 中的字符& 、 < 和 > 转换为安全的HTML序列。\n",
    "## ```html.unescape(s) ```将字符串 s 中的所有命名和数字字符引用 (例如 &gt;, &#62;, &#x3e;) 转换为相应的Unicode字符。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c69e8516",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"I ♥ Python's <standard library>.\""
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import html\n",
    "html.escape(\"This HTML fragment contains a <script>script</script> tag.\") \n",
    "\n",
    "html.unescape(\"I &hearts; Python's &lt;standard library&gt;.\") "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "ec1b6ccb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Not an odd minute.\n"
     ]
    }
   ],
   "source": [
    "# 三、if 、else、elif\n",
    "**if** 在if条件为true时执行  \n",
    "**else** 在if条件为false时执行  \n",
    "**elif** 在if条件为false、elif条件为true时执行  \n",
    "**代码块** 代码块是将源代码组织在一起的词法结构，构成自一个或多个声明和语句。Python 的代码块不使用大括号```{}```，而是使用冒号```:```和缩进。\n",
    "\n",
    "\n",
    "# 用if、eles判断时间是否为奇数分钟\n",
    "from datetime import datetime\n",
    "odds = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59]\n",
    "right_this_minute = datetime.today().minute\n",
    "if right_this_minute in odds:\n",
    "    print(\"This minute seems a little odd.\")\n",
    "else:\n",
    "    print(\"Not an odd minute.\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "63560f48",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Work, work, work.\n"
     ]
    }
   ],
   "source": [
    "# 用if、eles、elif判断是否为休息日\n",
    "import time\n",
    "today = time.strftime(\"%A\")\n",
    "if today == 'Saturday':\n",
    "    print('Party!')\n",
    "elif today == 'Sunday':\n",
    "    if condition == 'Headache':\n",
    "        print('Recover, then rest.')\n",
    "    else:\n",
    "        print('Rest.')\n",
    "else:\n",
    "    print('Work, work, work.')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4145546b",
   "metadata": {},
   "source": [
    "## 四、for循环、range循环\n",
    "**迭代** 是程序中对一组指令（或一定步骤）的重复。  \n",
    "**for循环** for循环可以遍历任何序列的项目，如一个列表或者一个字符串。  \n",
    "**range循环** range() 函数可创建一个整数列表，一般用在 for 循环中。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "9daa8463",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "# 循环迭代数字变量\n",
    "for i in [1, 2, 3]:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "218e63a9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "H\n",
      "i\n",
      "!\n"
     ]
    }
   ],
   "source": [
    "#循环迭代字符串变量\n",
    "for ch in \"Hi!\":\n",
    "    print(ch)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "6313ab40",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Head First Rocks!\n",
      "Head First Rocks!\n",
      "Head First Rocks!\n",
      "Head First Rocks!\n",
      "Head First Rocks!\n"
     ]
    }
   ],
   "source": [
    "#迭代指定的次数\n",
    "for num in range(5):\n",
    "    print('Head First Rocks!')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "51e53b4c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 5)"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#range 实验\n",
    "range(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "4ff0ff50",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2, 3, 4]"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "9647e850",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[5, 6, 7, 8, 9]"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(5, 10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "1b730733",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 2, 4, 6, 8]"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(0, 10, 2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "796f54dc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[10, 8, 6, 4, 2]"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(10, 0, -2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "8b099732",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(10, 0, 2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "dfa18a71",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[99,\n",
       " 98,\n",
       " 97,\n",
       " 96,\n",
       " 95,\n",
       " 94,\n",
       " 93,\n",
       " 92,\n",
       " 91,\n",
       " 90,\n",
       " 89,\n",
       " 88,\n",
       " 87,\n",
       " 86,\n",
       " 85,\n",
       " 84,\n",
       " 83,\n",
       " 82,\n",
       " 81,\n",
       " 80,\n",
       " 79,\n",
       " 78,\n",
       " 77,\n",
       " 76,\n",
       " 75,\n",
       " 74,\n",
       " 73,\n",
       " 72,\n",
       " 71,\n",
       " 70,\n",
       " 69,\n",
       " 68,\n",
       " 67,\n",
       " 66,\n",
       " 65,\n",
       " 64,\n",
       " 63,\n",
       " 62,\n",
       " 61,\n",
       " 60,\n",
       " 59,\n",
       " 58,\n",
       " 57,\n",
       " 56,\n",
       " 55,\n",
       " 54,\n",
       " 53,\n",
       " 52,\n",
       " 51,\n",
       " 50,\n",
       " 49,\n",
       " 48,\n",
       " 47,\n",
       " 46,\n",
       " 45,\n",
       " 44,\n",
       " 43,\n",
       " 42,\n",
       " 41,\n",
       " 40,\n",
       " 39,\n",
       " 38,\n",
       " 37,\n",
       " 36,\n",
       " 35,\n",
       " 34,\n",
       " 33,\n",
       " 32,\n",
       " 31,\n",
       " 30,\n",
       " 29,\n",
       " 28,\n",
       " 27,\n",
       " 26,\n",
       " 25,\n",
       " 24,\n",
       " 23,\n",
       " 22,\n",
       " 21,\n",
       " 20,\n",
       " 19,\n",
       " 18,\n",
       " 17,\n",
       " 16,\n",
       " 15,\n",
       " 14,\n",
       " 13,\n",
       " 12,\n",
       " 11,\n",
       " 10,\n",
       " 9,\n",
       " 8,\n",
       " 7,\n",
       " 6,\n",
       " 5,\n",
       " 4,\n",
       " 3,\n",
       " 2,\n",
       " 1]"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(99, 0, -1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ec54d31d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "565.6px",
    "left": "1228.8px",
    "top": "110.8px",
    "width": "212px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
